import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

/**
 * 重写路由的push方法
 */
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(error => error)
}

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Home',
        component: Home,
        children: [
            {
                path: '/',
                redirect: '/chatIndex',
            },
            {
                path: '/chatIndex',
                name: 'ChatIndex',
                meta: {keepAlive: true},
                component: () => import('../views/chat/ChatIndex.vue')
            },
            {
                path: '/friendList',
                name: 'FriendList',
                meta: {keepAlive: true},
                component: () => import('../views/chat/FriendList.vue')
            },
            {
                path: '/setting',
                name: 'Setting',
                meta: {keepAlive: true},
                component: () => import('../views/chat/Setting.vue')
            }
        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import( '../views/Login.vue')
    },
    {
        path: '/register',
        name: 'Register',
        component: () => import( '../views/Register.vue')
    }
]

const router = new VueRouter({
    routes
})

export default router
